home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2001 October
/
PCWorld_2001-10_cd.bin
/
Software
/
TemaCD
/
3dcanvas
/
3DCanv13.CAB
/
Create Face.CS
< prev
next >
Wrap
Text File
|
2001-06-02
|
6KB
|
203 lines
Language = VBScript
'*********************************************************************************
' Purpose: Creates a Face
'*********************************************************************************
Option Explicit 'require variable declarations
Sub Main (CanvasApp)
Dim Scene 'The current active scene
Dim SceneRootFrame 'The root frame of the scene
Dim Frame 'The frame for our object (face)
Dim Object 'The object we are creating (face)
Dim Face 'The face we are creating
Dim GridOriginX 'The 3D Canvas Grid's Origin (x)
Dim GridOriginY 'The 3D Canvas Grid's Origin (y)
Dim GridOriginZ 'The 3D Canvas Grid's Origin (z)
Dim GridSize 'The 3D Canvas Grid's Size
Dim GridInterval 'The 3D Canvas Grid's Interval
Dim Points 'The user's desired # of points
Dim NumericPoints 'Points converted to a number
Dim FirstPointX 'First point in face
Dim FirstPointY 'First point in face
Dim FirstPointZ 'First point in face
Dim AxisX 'Axis to rotate the start position around
Dim AxisY 'Axis to rotate the start position around
Dim AxisZ 'Axis to rotate the start position around
Dim Point 'Point we are creating
Dim NewPointX 'Point to add
Dim NewPointY 'Point to add
Dim NewPointZ 'Point to add
Dim BoxMinX 'The Object's Bounding Box
Dim BoxMinY 'The Object's Bounding Box
Dim BoxMinZ 'The Object's Bounding Box
Dim BoxMaxX 'The Object's Bounding Box
Dim BoxMaxY 'The Object's Bounding Box
Dim BoxMaxZ 'The Object's Bounding Box
Dim Material 'The Face's Material
'ask the user how many points s/he wants
Do
Points = InputBox("How many points would you like in the face?",,"4")
'if they entered anything
If Points <> "" Then
'they could have entered anything so ensure it is valid
On Error Resume Next
NumericPoints = clng(Points)
Err.Clear
On Error Goto 0
'Let them know we had a problem
If NumericPoints < 3 Then
Msgbox "3 is the minimum number of points", vbInformation
End If
End if
Loop Until NumericPoints >= 3 Or Points = ""
'If they entered anything continue
If Points <> "" Then
'get the scene
Set Scene = CanvasApp.GetActiveScene
'get the root frame
Set SceneRootFrame = Scene.GetRootFrame
'create a frame for the object (face)
Set Frame = Scene.CreateFrame
'add it to the scene
SceneRootFrame.AddChild Frame
'give the frame a name - note that we can't do this
'until the frame is added to the scene
Frame.SetName "Face Frame"
'create an object
Set Object = Scene.CreateObject()
'add the face to the object
Set Face = Object.CreateFace
'add a dummy normal to the object (we need one to add the points)
Object.AddNormal 0,0,-1
'set the FirstPoint
FirstPointX = 0
FirstPointY = .5
FirstPointZ = 0
'we're going to make an exception if they want four faces
'a quad will look wrong if we just rotate around a point
If NumericPoints = 4 Then
'add the quad points to the object
Object.AddPoint -.5,-.5,0
Object.AddPoint -.5,.5,0
Object.AddPoint .5,.5,0
Object.AddPoint .5,-.5,0
'add the points and the normal to the face
Face.AddPointAndNormal 0,0
Face.AddPointAndNormal 1,0
Face.AddPointAndNormal 2,0
Face.AddPointAndNormal 3,0
Else
'add the points to the object
For Point = 0 to NumericPoints - 1
'rotate the FirstPoint to get a NewPoint
CanvasApp.RotatePoint FirstPointX, FirstPointY, FirstPointZ, 0, 0, -1, 6.2831853 / NumericPoints * Point, NewPointX, NewPointY, NewPointZ
'add the NewPoint to the object
Object.AddPoint NewPointX, NewPointY, NewPointZ
'add the point to the face
Face.AddPointAndNormal Point, 0
Next
End if
'Create an appropriate material for the face
Set Material = Scene.CreateMaterial
'make it a nice color
Material.SetColor .894,.773,.788
'set the default diffuse value
Material.SetDiffuse 60
'set the default ambient value
Material.SetAmbient 20
'apply the material to the face
Face.SetMaterial Material
'add the object to the created frame
'this also triggers the update to the database
Frame.AddObject Object
'set the object name - note that we can't do this until
'the object is added to a frame
Object.SetName "Face"
'Now that we know the size of the object let's set the position of the frame
'so the face is visible
'get the 3D Canvs grid details
CanvasApp.GetGridDetails GridOriginX, GridOriginY, GridOriginZ, GridSize, GridInterval
'get the object's dimensions
Object.GetBoundingBox BoxMinX, BoxMinY, BoxMinZ, BoxMaxX, BoxMaxY, BoxMaxZ
'Center the Object's Frame on the Scene and have the object sitting nicely
'on the surface
Frame.SetPosition SceneRootFrame, 0, GridOriginX + GridSize / 2, GridOriginY - BoxMinY, GridOriginZ + GridSize /2
End If
End Sub